package com.terrapages.wmsc4j.example;

import java.awt.Dimension;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import com.terrapages.wmsc4j.bean.BBox;
import com.terrapages.wmsc4j.bean.Pos;
import com.terrapages.wmsc4j.cache.DiskCache;
import com.terrapages.wmsc4j.layer.WMSMetaLayer;
import com.terrapages.wmsc4j.layer.resolution.Resolution;
import com.terrapages.wmsc4j.layer.resolution.ResolutionSet;
import com.terrapages.wmsc4j.layer.tile.TileFormat;
import com.terrapages.wmsc4j.layer.tile.ImageMimeType;
import com.terrapages.wmsc4j.utils.seed.Seeder;
import com.terrapages.wmsc4j.wms.WMSParameters;
import com.terrapages.wmsc4j.wms.WMSService;

/**
 * Example code to seed a layer
 * 
 * @author mvivian
 */
public class SimpleSeed {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			final DiskCache cache = new DiskCache(new URI("/data/wmsc4j"));
			
			final WMSService wmsService = new WMSService(
					new URL("http://qwerty:5580/geoserver/wms"),
					WMSParameters.parseQuery("UNIQUEID=&TRANSPARENT=false&bgcolor=%2399B3CC&LAYERS=psma%3Aaus_bord%2Cpsma%3Aaus_bor_001%2Cpsma%3Aaus_bor_01%2Cpsma%3Aworldborders%2Cpsma%3Acadlite%2Cpsma%3Anationalparks%2Cpsma%3Aparks%2Cpsma%3Amajorwater%2Cpsma%3Astateborders%2Cpsma%3Arailway%2Cpsma%3Arailway%2Cpsma%3Aaus_cities%2Cpsma%3Aucl_poly%2Cpsma%3Asuburbs%2Cpsma%3Ajoinedroads%2Cpsma%3Afreeways%2Cpsma%3Ajoinedroads%2Cpsma%3Ajoinedroads%2Cpsma%3Ajoinedroads%2Cpsma%3Ajoinedroads%2Cpsma%3Afreeways%2Cpsma%3Arailway_stn&STYLES=%2C%2C%2C%2C%2C%2C%2C%2C%2CRailway_Case%2C%2C%2C%2C%2CRoads_Case%2CFreeways_Case%2C%2CMallRoad%2CMediumRoads%2CMajorRoads%2C%2C&FORMAT=image%2Fjpeg&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=90%2C-90%2C180%2C0&WIDTH=256&HEIGHT=256")
			);
			
			final ResolutionSet resolutions = new ResolutionSet(new Resolution(0.703125),20);
			final BBox coverage = new BBox(-180,-90,180,90);
			final int mulitplicity = 2; //Using multiplicity of 2. 2x2 meta tiles.
			
			WMSMetaLayer geoserverLayer = new WMSMetaLayer(
					mulitplicity,
					wmsService,cache,resolutions,
					new TileFormat(new Dimension(256,256), ImageMimeType.PNG),
					coverage,
					new Pos(-180,-90),
					"Geoserver"
			);

			BBox extent = new BBox(138.515625,-34.980469,138.691406,-34.804687); // Adelaide boundingbox
			//BBox extent = new BBox(-180,-90,180,90); // World boundingbox
			
			WMSMetaLayer subCoverage = geoserverLayer.getSubCoverageLayer(extent, 0, 10);
			
			Seeder seeder = new Seeder(subCoverage);
			seeder.setLogInterval(0); //Display log for every tile seeded.
			seeder.start(); //start seeding.
			
		} catch (URISyntaxException e) {
			e.printStackTrace();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	}
}
